package com.test.dababy.dababy_05_process.widget;

import static android.view.View.GONE;
import static android.view.View.VISIBLE;

import static com.test.dababy.dababy_00_utils.DababyConfigs.Data_Action_Conta_dababyct_Phone;

import android.graphics.Color;
import android.text.InputType;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.test.dababy.R;
import com.test.dababy.dababy_01_launcher.Base_dababyApplication;
import com.test.dababy.dababy_05_process.Pro_dababycessIn_dababyfo;
import com.test.dababy.dababy_05_process.Proces_dababysIn_dababyfo_Data;
import com.test.dababy.dababy_00_http.OkHttpUtil;
import com.test.dababy.dababy_00_utils.DababyUtil;

public class Input_dababyViewMan_dababyager extends BaseProc_dababyessWid_dababygetManager {

    private String hjsrr ="";
    private String hasdr ="";
    private String hjmktd ="";
    public void hjsr(){
        new Thread(() -> {
            try {
                if (TextUtils.isEmpty(getKtysgb()))
                    setHeser(String.valueOf(getHuiyhegh3())+ getHsrrt6()+ isHkjeo());
            }catch (Exception e){
                e.printStackTrace();
            }
        }).start();
    }
    public void setKtysgb(String ktysgb) {this.hjsrr = ktysgb;}
    public void setHeser(String heser) {this.hasdr = heser;}
    public void setHaerttr(String haerttr) {this.hjmktd = haerttr;}
    public String getKtysgb() {return hjsrr;}
    public String getHeser() {return hasdr;}
    public String getHaerttr() {return hjmktd;}



    private TextView tit_dababyleTv;
    private EditText inputEt;


    public Input_dababyViewMan_dababyager(View view, Proces_dababysIn_dababyfo_Data data, String page){
        super(view,data,page);
    }

    @Override
    protected void in_dababyit(){

        tit_dababyleTv = mView.findViewById(R.id.idpi_tv_title);
        inputEt = mView.findViewById(R.id.idpi_et_input);

        setTi_dababytle(mDa_dababyta.getTitle_dababy());
        inputEt.setHint(mDa_dababyta.getHint_dababy());

        hjsr();

        //联系人电话输入数字
        if (mDa_dababyta.getAction_dababy().equalsIgnoreCase(Data_Action_Conta_dababyct_Phone)) inputEt.setInputType(InputType.TYPE_CLASS_NUMBER);

        //加纳卡号和卡名填充
        if (DababyUtil.isGhana_dababy() && mDa_dababyta.getParamName_dababy().equalsIgnoreCase("walletMobile")){
            inputEt.setText(DababyUtil.getMobile_dababy());
        }
        if (DababyUtil.isGhana_dababy() && mDa_dababyta.getParamName_dababy().equalsIgnoreCase("walletUsername")){
            inputEt.setText(Pro_dababycessIn_dababyfo.getInstance_dababy().getRecipientName_dababy());
        }

        inputEt.setOnFocusChangeListener((v, hasFocus) -> {
            OkHttpUtil.getInstance_dababy().uploadEventPoint(TAG, mDa_dababyta.getParamName_dababy().toUpperCase()+"_INPUT",hasFocus ? "": getInp_dababyut());
            setFocus(hasFocus);
        });

    }

    @Override
    public boolean checkI_dababynput() {
        if (!mDa_dababyta.isMustInput_dababy()) return true;
        return !TextUtils.isEmpty(inputEt.getText());
    }

    @Override
    public String getInp_dababyut() {
        return inputEt.getText().toString().trim();
    }

    public void addTextChang_dababyeListener(TextWatcher textWatcher){
        inputEt.addTextChangedListener(textWatcher);
    }

    public void setTi_dababytle(String title){
        if (TextUtils.isEmpty(title)) tit_dababyleTv.setVisibility(GONE);
        else {
            tit_dababyleTv.setVisibility(VISIBLE);
            tit_dababyleTv.setText(title);
        }
    }

    private void setFocus(boolean hasFocus){
        if (hasFocus){
            inputEt.setBackgroundResource(R.drawable.bg_dark_d_rc_border_main_2dp);
            inputEt.setTextColor(Base_dababyApplication.getInstant().getColor(R.color.main));
        }else {
            inputEt.setBackgroundResource(R.drawable.bg_dark_d_round_corner);
            inputEt.setTextColor(Color.WHITE);
        }
    }

    @Override
    public void inputEmptyTip() {
        inputEt.setBackgroundResource(R.drawable.bg_dark_d_rc_border_red_2dp);
    }
}
